const { backendApiUrl } = require('../../utils/config');
import { apiRequest } from '../_utils/apiRequest';

/**
 * 提交订单
 * @param {object} orderData - 订单数据
 * @returns {Promise} - 返回订单提交结果
 */
export const submitOrder = (orderData) => {
  return apiRequest({
    url: `${backendApiUrl}/orders`,
    method: 'POST',
    data: orderData,
  });
};

/**
 * 更新订单状态
 * @param {string} orderId - 订单 ID
 * @param {string} orderStatus - 更新后的订单状态
 * @returns {Promise} - 返回更新结果
 */
export const updateOrderStatus = (orderId, orderStatus) => {
  return apiRequest({
    url: `${backendApiUrl}/orders/me/${orderId}`,
    method: 'PUT',
    data: { status: orderStatus },
  });
};

/**
 * 关闭失败订单
 * @param {string} orderId - 订单 ID
 * @returns {Promise} - 返回关闭失败订单的结果
 */
export const closeFailOrder = (orderId) => {
  return apiRequest({
    url: `${backendApiUrl}/orders/closeFailOrder/${orderId}`,
    method: 'POST',
  });
};

module.exports = { submitOrder, updateOrderStatus, closeFailOrder };
